﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FastReflectionLib;
using System.Web;
using SZHL.UI.AppCode;
using SZHL.Data;
using Newtonsoft.Json;
using System.Data;

namespace SZHL.UI.API
{
    public class DXGLManage : IWsService
    {
        public void ProcessRequest(HttpContext context, ref Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            MethodInfo methodInfo = typeof(DXGLManage).GetMethod(msg.Action.ToUpper());
            DXGLManage model = new DXGLManage();
            methodInfo.FastInvoke(model, new object[] { context, msg, P1, P2, UserInfo });
        }
        /// <summary>
        /// 添加短信内容并发送短信
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void ADDDXGL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            try
            {
                ZH_DXGL dxgl = JsonConvert.DeserializeObject<ZH_DXGL>(P1);
                dxgl.CRUser = UserInfo.User.UserName;
                dxgl.CRDate = DateTime.Now;
                bool isNow = dxgl.SendTime == null;
                dxgl.SendTime = dxgl.SendTime == null ? DateTime.Now : dxgl.SendTime;
                if (isNow)
                {
                    //发送短信
                    CommonHelp.SendSMS(dxgl.dxnums, dxgl.dxContent);
                    dxgl.isSend = "Y";
                }
                new ZH_DXGLB().Insert(dxgl);

            }
            catch (Exception ex)
            {
                msg.ErrorMsg = ex.Message;
            }
        }
        /// <summary>
        /// 获取短信列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">短信内容</param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETDXGLLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = "";
            if (P1 != "")
            {
                strWhere = string.Format(" Where dxContent like '%{0}%'", P1);
            }
            string strSql = string.Format("select ID,dxContent,dxnums,SendTime,CRUser,CRDate from ZH_DXGL {0} order by CRDate desc", strWhere);
            DataTable dt = new ZH_DXGLB().GetDTByCommand(strSql);
            msg.Result = dt;
        }
        /// <summary>
        /// 删除短信信息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">短信信息Id</param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void DELDXGL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            try
            {

                new ZH_DXGLB().Delete(d => d.ID.ToString() == P1);

            }
            catch (Exception ex)
            {
                msg.ErrorMsg = ex.Message;
            }
        }
    }
}